//
//  TravelAndFilmCollectionViewCell.m
//  TravelFollowYourHeart
//
//  Created by ENERGY on 2018/1/22.
//  Copyright © 2018年 Lwx. All rights reserved.
//

#import "FilmCollectionViewCell.h"
#import "TravelLikeButton.h"
@interface FilmCollectionViewCell()
@property (nonatomic, strong)UIImageView * iconImage;
@property (nonatomic, strong)UILabel * nameLab;
@property (nonatomic, strong)UILabel * dataLab;
@property (nonatomic, strong)UIImageView * contentImage;
@property (nonatomic, strong)UILabel * contentLab;
@property (nonatomic, strong)TravelLikeButton * commentBtn;
@property (nonatomic, strong)TravelLikeButton * likeBtn;
@property (nonatomic, strong)UIButton * videoBtn;
@property (nonatomic, strong)NSString * filmID;
@end
@implementation FilmCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self.contentView addSubview:self.iconImage];
        [self.contentView addSubview:self.nameLab];
        [self.contentView addSubview:self.dataLab];
        [self.contentView addSubview:self.contentImage];
        [self.contentView addSubview:self.contentLab];
        [self.contentView addSubview:self.commentBtn];
        [self.contentView addSubview:self.likeBtn];
        [self.contentView addSubview:self.videoBtn];
        self.contentView.backgroundColor = [UIColor whiteColor];
    }return self;
}

- (UIButton *)commentBtn{
    if (!_commentBtn) {
        _commentBtn = [[TravelLikeButton alloc] init];
        [_commentBtn setImage:[UIImage imageNamed:@"mp_pinglun"] forState:UIControlStateNormal];
        [_commentBtn addTarget:self action:@selector(commentBtnClick) forControlEvents:UIControlEventTouchUpInside];
        [_commentBtn setBackgroundColor:[UIColor clearColor]];
        [_commentBtn setTitle:@"3321" forState:UIControlStateNormal];
        _commentBtn.titleLabel.font = DEF_FontSize_14;
        [_commentBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
//        _commentBtn.backgroundColor = [UIColor redColor];
    }return _commentBtn;
}

- (UIButton *)likeBtn{
    if (!_likeBtn) {
        _likeBtn = [[TravelLikeButton alloc] init];
        [_likeBtn setImage:[UIImage imageNamed:@"icon_shoucang"] forState:UIControlStateNormal];
        [_likeBtn setImage:[UIImage imageNamed:@"icon_yishoucang"] forState:UIControlStateSelected];
        [_likeBtn setBackgroundColor:[UIColor clearColor]];
        [_likeBtn setTitle:@"3321" forState:UIControlStateNormal];
        _likeBtn.titleLabel.font = DEF_FontSize_14;
        [_likeBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [_likeBtn addTarget:self action:@selector(likeBtnClick:) forControlEvents:UIControlEventTouchUpInside];
//        _likeBtn.backgroundColor = [UIColor yellowColor];

    }return _likeBtn;
}

- (UILabel *)nameLab{
    if (!_nameLab) {
        _nameLab = [[UILabel alloc] init];
        _nameLab.text = @"叫啥名";
        _nameLab.font = DEF_FontSize_14;
        _nameLab.textColor = [UIColor blackColor];
        _nameLab.textAlignment = NSTextAlignmentLeft;
        
    }return _nameLab;
}

- (UILabel *)dataLab{
    if (!_dataLab) {
        _dataLab = [[UILabel alloc] init];
        _dataLab.text = @"2017年00月00日 00：00：00";
        _dataLab.font = DEF_FontSize_12;
        _dataLab.textColor = [UIColor grayColor];
        _dataLab.textAlignment = NSTextAlignmentLeft;
    }return _dataLab;
}

- (UILabel *)contentLab{
    if (!_contentLab) {
        _contentLab = [[UILabel alloc] init];
        _contentLab.text = @"hahah";
        _contentLab.font = DEF_FontSize_14;
        _contentLab.textColor = [UIColor blackColor];
        _contentLab.textAlignment = NSTextAlignmentLeft;
    }return _contentLab;
}

- (UIImageView *)iconImage{
    if (!_iconImage) {
        _iconImage = [[UIImageView alloc] init];
//        _iconImage.backgroundColor = [UIColor redColor];
    }return _iconImage;
}

- (UIButton *)videoBtn{
    if (!_videoBtn) {
        _videoBtn = [[UIButton alloc] init];
        [_videoBtn addTarget:self action:@selector(videoBtnClick) forControlEvents:UIControlEventTouchUpInside];
    }return _videoBtn;
}

- (UIImageView *)contentImage{
    if (!_contentImage) {
        _contentImage = [[UIImageView alloc] init];
        [_contentImage setImage:[UIImage imageNamed:@"img_list2111"]];
    }return _contentImage;
}

- (void)layoutSubviews{
    [super layoutSubviews];

    int border = 10/HEIGHT_5S_SCALE;
    int iconImageW = 30/WIDTH_5S_SCALE;
    int commentBtnW = 60/WIDTH_5S_SCALE;
    int commentBtnH = 20/HEIGHT_5S_SCALE;
    self.iconImage.frame = CGRectMake(border, border, iconImageW, iconImageW);
    self.nameLab.frame = CGRectMake(self.iconImage.right + 5, self.iconImage.top, SCREEN_WIDTH - 2*border - self.iconImage.width - 5, iconImageW / 2);
    self.dataLab.frame = CGRectMake(self.nameLab.left, self.nameLab.bottom, self.nameLab.width, self.nameLab.height);
    self.contentImage.frame = CGRectMake(0, self.dataLab.bottom + border, SCREEN_WIDTH, 150 / HEIGHT_5S_SCALE);
    self.contentLab.frame = CGRectMake(border / 2, self.contentImage.bottom, SCREEN_WIDTH - border, 20);
    self.commentBtn.frame = CGRectMake(SCREEN_WIDTH - 2* commentBtnW - border, self.contentLab.bottom + border / 2, commentBtnW, commentBtnH);
    self.likeBtn.frame = CGRectMake(self.commentBtn.right, self.commentBtn.top, commentBtnW, commentBtnH);
    self.likeBtn.centerY = self.commentBtn.centerY;
    self.videoBtn.frame = self.contentImage.frame;
}

- (void)commentBtnClick{
    NSLog(@"查看评论");
    if (self.block) {
        self.block();
    }
}

- (void)likeBtnClick:(UIButton *)btn{
    NSLog(@"收藏");
    NSString * btnText = btn.titleLabel.text;
    btn.selected = !btn.selected;
    if (self.likeBlock) {
        self.likeBlock();
    }
    if (btn.selected) {
        [btn setTitle:[NSString stringWithFormat:@"%i", [btnText intValue] + 1] forState:UIControlStateNormal];
    }else{
        [btn setTitle:[NSString stringWithFormat:@"%i", [btnText intValue] - 1] forState:UIControlStateNormal];
    }
}

- (void)videoBtnClick{
//    NSLog(@"美拍视频，接到视频地址后，代理传值");
    if (self.videoBlock) {
        self.videoBlock();
    }
}

- (void)setModelData:(FilmCollectionModelData *)modelData{
    _modelData = modelData;
    [self.iconImage sd_setImageWithURL:[NSURL URLWithString:modelData.avatar]];
    self.nameLab.text = modelData.nickname;
    self.dataLab.text = modelData.addtime;
    [self.contentImage sd_setImageWithURL:[NSURL URLWithString:modelData.video_pic]];
    self.contentLab.text = modelData.content;
    [self.commentBtn setTitle:modelData.comments forState:UIControlStateNormal];
    self.filmID = modelData.filmID;
    if ([modelData.is_like isEqualToString:@"未点赞"]) {
        self.likeBtn.selected = NO;
    }else{
        self.likeBtn.selected = YES;
    }
    [self.likeBtn setTitle:modelData.likes forState:UIControlStateNormal];
}


@end
